package com.example.fina2202.day07;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class StudentTest {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        for (int i=2;i<=10;i++){
            Student student = new Student(i,"student"+i,20+i);
            list.add(student);
        }
        Student student1 = new Student(1,"tom",21);
        list.add(student1);
        list.forEach(student -> System.out.println(student));
        System.out.println("----------------------------------");
        //对list排序,根据id升序排列
//        Collections.sort(list);
//        list.forEach(student -> System.out.println(student));

        //按照学生age降序排列
//        Collections.sort(list, new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o2.getAge()-o1.getAge();
//            }
//        });
//        list.forEach(student -> System.out.println(student));

        //按照name升序排列
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getName().compareTo(o1.getName());
            }
        });
        list.forEach(student -> System.out.println(student));



    }
}
